function in_array(search, array){
    for(var i in array){
        if(array[i] == search){
            return true;
        }
    }
    return false;
}

function doPost(obj, url, post_data, callback)
{
    var defaultError = arguments[4] ? arguments[4] : true;
    if (url == '' || url =='#')
        return false;
    $.post(url, post_data,
        function(data, statusText, jqXHR){
            if (in_array(data.code, [301, 302, 303])) {
                location.href = data.location
                return;
            }
            if (defaultError && data.code != 0) {
                alert(data.msg);
                return;
            }
            if (callback)
                callback(obj, data);
    }, 'json');
}